"""

Task that generates new individuals.

"""

# Import schema modules
from tasks.operators import initialization_operator
from tasks.libs import constants as sc

# Import DEXEN modules
from dexen.user.libs import constants as dc
from dexen.user.libs import server_api

""" GLOBALS """
pop_api = server_api.PopAPIFactory()

def evaluate(individuals = None):
    """
    Task that:
        - gets the number of individuals to be generated from the server
        - creates new individuals
        - uploads the new individuals back to the server
    """
    print "I am in initialisation" 
    
    # Get the number of individuals to be processed for the global data saved
    # on the server. These numbers are set in the config function for this 
    # schema.
    count_for_initialisation = pop_api.getGlobalData()[sc.INITIALISATION]
    
    # Use the operator to generate the new individuals
    new_individuals = initialisation_operator.executeInitialisation(count_for_initialisation)
    
    # Upload individuals
    pop_api.uploadIndividuals(new_individuals)


